package com.javasm.controller.B2CController;

import com.javasm.common.http.AxiosResult;
import com.javasm.common.page.PageResult;
import com.javasm.domin.criteria.orderCriteria.OrderGoodsCriteria;
import com.javasm.domin.entity.goodsEntity.GdBrand;
import com.javasm.domin.entity.goodsEntity.GdColour;
import com.javasm.domin.entity.goodsEntity.GdGoods;
import com.javasm.domin.entity.goodsEntity.GdType;
import com.javasm.domin.entity.orderEntity.B2cOrderGoods;
import com.javasm.domin.vo.orderVo.OrderGoodVo;
import com.javasm.mapper.B2cOrderMapper.OrderGoodsMapper;
import com.javasm.mapper.goodsMapper.GdBrandMapper;
import com.javasm.mapper.goodsMapper.GdColourMapper;
import com.javasm.mapper.goodsMapper.GdGoodsMapper;
import com.javasm.mapper.goodsMapper.GdTypeMapper;
import com.javasm.service.B2cOrderService.OrderGoodsService;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author：liyangsong
 * @Version：1.0
 * @Date：2021/11/20-18:57
 * @Since:jdk1.8
 * @Description:
 */

@RestController
@RequestMapping("/orderGoods")
@RequiredArgsConstructor
public class OrderGoodsController {

    private final OrderGoodsService orderGoodsService;

    private final GdGoodsMapper goodsMapper;

    private final GdBrandMapper gdBrandMapper;

    private final GdColourMapper gdColourMapper;
    private final GdTypeMapper gdTypeMapper;
    private final OrderGoodsMapper orderGoodsMapper;

    /**
     * 根据订单id 得到该订单包含的商品
     *
     * @param orderGoodsCriteria
     * @return
     */
    @RequestMapping("/{orderId}")
    public AxiosResult<List<B2cOrderGoods>> find(OrderGoodsCriteria orderGoodsCriteria) {
        List<B2cOrderGoods> goodByOrderId = orderGoodsService.findGoodByOrderId(orderGoodsCriteria);
        return AxiosResult.success(goodByOrderId);
    }

    /**
     * 查询所有商品
     *
     * @return
     */
    @RequestMapping("/findAll")
    public List<B2cOrderGoods> find() {
        return orderGoodsService.list();
    }

    /**
     * 查询商品统计
     *
     * @return
     */
    @RequestMapping("/page")
    public AxiosResult<PageResult<OrderGoodVo>> show(OrderGoodsCriteria orderGoodsCriteria) {
        PageResult<OrderGoodVo> page = orderGoodsService.findPage(orderGoodsCriteria);
        return AxiosResult.success(page);
    }

    /**
     * 查询颜色
     */
    @RequestMapping("/colorList")
    public AxiosResult<List<GdColour>> show() {
        List<GdColour> gdColours = gdColourMapper.selectList(null);
        return AxiosResult.success(gdColours);
    }

    /**
     * 查询商品所有分类
     */
    @RequestMapping("/typeList")
    public AxiosResult<List<GdType>> type() {
        List<GdType> gdTypes = gdTypeMapper.selectList(null);
        System.out.println(gdTypes);
        return AxiosResult.success(gdTypes);
    }

    /**
     * 查询所有商品品牌
     *
     * @return
     */
    @RequestMapping("/brandList")
    public AxiosResult<List<GdBrand>> brand() {
        List<GdBrand> gdBrands = gdBrandMapper.selectList(null);
        return AxiosResult.success(gdBrands);
    }

    @RequestMapping("/good")
    public AxiosResult<List<OrderGoodVo>> ooo(OrderGoodsCriteria orderGoodsCriteria) {
        ArrayList<Serializable> orderIdList = new ArrayList<>();
        orderIdList.add(1);
        orderIdList.add(2);
        orderIdList.add(3);
        orderGoodsCriteria.setOrderIdList(orderIdList);
        List<OrderGoodVo> orderGoodByOrderIdList = orderGoodsService.findOrderGoodByOrderIdList(orderGoodsCriteria);
        return AxiosResult.success(orderGoodByOrderIdList);
    }

    /**
     * 批量查询商品
     *
     * @param
     */
    @RequestMapping("/batch/{idList}")
    public AxiosResult<List<GdGoods>> addOrderGoods(@PathVariable List<Serializable> idList) {
        List<GdGoods> gdGoods = goodsMapper.selectBatchIds(idList);
        return AxiosResult.success(gdGoods);
    }


    /**
     * 根据订单id 得到该订单包含的商品
     *
     * @param
     * @return
     */
    @RequestMapping("/find/{orderId}")
    public AxiosResult<List<B2cOrderGoods>> show(@PathVariable Serializable orderId) {
        List<B2cOrderGoods> orderGoodsByOrderId = orderGoodsMapper.findOrderGoodsByOrderId(orderId);

//        List<B2cOrderGoods> goodByOrderId = orderGoodsService.findGoodByOrderId(orderGoodsCriteria);
        return AxiosResult.success(orderGoodsByOrderId);
    }


}
